package com.los;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * @program: java8
 * @description: lambda表达式
 * @author: Yujuan
 * @create: 2018-06-11 17:00
 **/
public class LambdaException {
    public static void main(String[] args) {
        Comparator<Apple> comparator=new Comparator<Apple>() {
            @Override
            public int compare(Apple o1, Apple o2) {
                return o1.getWeight().compareTo(o2.getWeight());
            }
        };
        List<Apple> apples= Arrays.asList(new Apple("Green",100),new Apple("Red",100),new Apple("Blue",100));
        apples.sort(comparator);

        apples.sort((o1,o2)-> o1.getWeight().compareTo(o2.getWeight()));

        apples.sort(Comparator.comparing(Apple::getColor));

        Function<String,Integer> fLambda=s -> s.length();

        Predicate<Apple> pLambda=apple -> apple.getColor().equals("green");

        Runnable runnable=()->{};

        Supplier<Apple>  appleSupplier=Apple::new;

        apples.stream().forEach(apple -> System.out.println(apple.getColor()));

        apples.stream().forEach(System.out::println);

        Function<String,Integer> function=Integer::parseInt;
        Integer a=function.apply("123");
    }
}
